//
//  RW_HomeItemViewModel.m
//  SleepApp
//
//  Created by MAC on 2021/3/29.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_HomeItemViewModel.h"
#import "RW_MusicItemCollectionViewCell.h"
#import "RW_PlaySingleCollectionReusableView.h"

@implementation RW_HomeItemViewModel

/** 获取歌曲列表数据模型 */
-(void)getCellSuccess:(void(^)(NSArray<WLBaseCollectionViewLayerSection *> *response))success
                 fail:(void(^)(NSError *error))fail{
    [[[RW_SingleModel getSingleSongListId:self.singleModel.xid] then:^id(RW_SingleModel *value) {
        if (success){
            success([self getSectionDataList:value]);
        }
        return nil;
    }] catch:fail];
}



#pragma mark -- 视图数据获取
-(NSArray<WLBaseCollectionViewLayerSection *> *)getSectionDataList:(RW_SingleModel *)singleModel{
    NSMutableArray *array = [NSMutableArray array];

    WLBaseCollectionViewLayerSection *section = [[WLBaseCollectionViewLayerSection alloc]init];
    section.insetForSection = UIEdgeInsetsMake(5, 5, 5, 5);
    section.horizontalSection = 5;
    section.horizontalMaxWidth = Main_Screen_Width;
    section.horizontalCount = 3;
    section.verticalSection = 5;

    CGSize itemSize = [section getCellSizeHeight:[section getCellWidth]];

    for (RW_SongModel *songModel in singleModel.list){
        RW_MusicItemCollectionViewCellModel *model = [[RW_MusicItemCollectionViewCellModel alloc]init];
        model.songModel = songModel;

        [section.item addObject:[RW_MusicItemCollectionViewCell getRow:model cellSize:itemSize]];
    }
    [array addObject:section];
    return array;
}
@end
